﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using CMSApplication.Models;
using System.IO;
using CMSApplication.DataDictionaries;

namespace CMSApplication.Controllers
{
    public class AdministrationController : Controller
    {
        //
        // GET: /Administration/

        public ActionResult Index()
        {

            return View();
        }

        public ActionResult AddNewSite()
        {
            return View();
        }

        [HttpPost]
        public void SaveMarkdown(string title, string url, string content)
        {
            var site = new Site();      //TODO : remove when below code works
            //var site = new Site {
            //    site_title= title,
            //        site_url = url,
            //        site_content = content
            //    };
            
            using (var db = new CMSContext())
            {
                db.Sites.Add(site);
                db.SaveChanges();
            };
            
            //generated ID is already there after db.SaveChanges()

            //if not in the cache add it. May belong in AddNewSite()
            if (!Cache.SiteCache.Keys.Contains(site.site_title))
            {
                Cache.SiteCache.TryAdd(site.site_title, site);
            }
        }
    }
}